package com.btsk.service.impl;

import java.io.Serializable;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.criterion.DetachedCriteria;

import com.btsk.dao.GenericDao;
import com.btsk.service.GenericManager;


public class GenericManagerImpl<T, PK extends Serializable> implements GenericManager<T, PK>
{

    /**
     * Log variable for all child classes. Uses LogFactory.getLog(getClass()) from Commons Logging
     */
    protected final Log log = LogFactory.getLog(getClass());

    /**
     * GenericDao instance, set by constructor of child classes
     */
    protected GenericDao<T, PK> dao;

    public GenericManagerImpl()
    {
    }

    public GenericManagerImpl(GenericDao<T, PK> genericDao)
    {
        this.dao = genericDao;
    }

    /**
     * {@inheritDoc}
     */
    public List<T> getAll()
    {
        return dao.getAll();
    }

    /**
     * {@inheritDoc}
     */
    public T get(PK id)
    {
        return dao.get(id);
    }

    /**
     * {@inheritDoc}
     */
    public boolean exists(PK id)
    {
        return dao.exists(id);
    }

    /**
     * {@inheritDoc}
     */
    public T save(T object)
    {
        return dao.save(object);
    }

    /**
     * {@inheritDoc}
     */
    public void remove(PK id)
    {
        dao.remove(id);
    }

    public List<T> findByCriteria(DetachedCriteria detachedCriteria)
    {
        return dao.findByCriteria(detachedCriteria);
    }

    public List<T> findByCriteria(DetachedCriteria criteria, int firstResult, int maxResults)
    {
        return dao.findByCriteria(criteria, firstResult, maxResults);
    }

    public int findCountsBycriteria(DetachedCriteria criteria)
    {
        return dao.findCountsBycriteria(criteria);
    }
}
